<template>
    <!-- 日常资料管理 -->
    <base-breadcrumb class="allPlan">
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <!-- <title-name title="图纸列表"></title-name> -->
            <!-- 表格 -->
            <list-table
                ref="table"
                :pageKeys="['pageNum', 'pageSize', 'totalSize']"
                :columns="columns"
                :startIndex="1"
                :request="loadData"
                :exportPermission="{ select: 'tm_027_exp_06', all: 'tm_027_exp_06' }"
                :exportConfig="{ use: true, select: $route.meta.title, all: $route.meta.title }"
            >
                <!-- 新增 -->
                <a-button
                    v-btnPermission="'tm_027_add_01'"
                    slot="prefix"
                    class="mb12"
                    icon="plus"
                    type="primary"
                    @click="handleManage(2)"
                    >新增</a-button
                >
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                        <a v-btnPermission="'tm_027_loo_04'" @click="handleManage(0, record)">查看</a>
                        <!-- 编辑 -->
                        <span
                            v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                            v-btnPermission="'tm_027_edi_02'"
                        >
                            <a-divider type="vertical" />
                            <a @click="handleManage(1, record)">编辑</a>
                        </span>
                        <!-- 作废 -->
                        <!-- <span v-if="record.auditStatus == 'PAST'" v-btnPermission="'bm_019_tov_05'">
                        <a-divider type="vertical" />
                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
                    </span> -->
                        <!-- 删除 -->
                        <span v-if="record.auditStatus != 'SUBMITTED'" v-btnPermission="'tm_027_del_03'">
                            <a-divider type="vertical"></a-divider>
                            <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                        </span>

                        <span
                            v-if="
                                record.auditStatus === 'PAST' ||
                                record.auditStatus === 'SUBMITTED' ||
                                record.auditStatus === 'REJECTED'
                            "
                            v-btnPermission="'tm_027_loo_04'"
                        >
                            <a-divider type="vertical" />
                            <approval-button :id="record.id" :auditStatus="record.auditStatus" />
                        </span>
                    </MoreButton>
                </span>

                <span slot="auditStatusName" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getList, getCount, deleteList } from '@/api/technical/dailyDataManag'
// import { getDrawDesignList, delDrawDesign, getStatistical } from '@/api/technical/designFM'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import MoreButton from '@/components/MoreButton'
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        }
    },
    {
        title: '所属分公司',
        dataIndex: 'branchCompanyName',
        ellipsis: true
    },
    {
        title: '所属项目',
        width: 300,
        dataIndex: 'projectName',
        ellipsis: true
    },
    {
        title: '收发文类型',
        dataIndex: 'messageTypeName',
        ellipsis: true
    },
    {
        title: '文件名称',
        dataIndex: 'messageName',
        width: 200,
        ellipsis: true
    },
    // {
    //     title: '文件编号',
    //     dataIndex: 'messageNumber',
    //     width: 200,
    //     ellipsis: true
    // },
    {
        title: '内容摘要',
        dataIndex: 'messageAbstract',
        ellipsis: true
    },
    {
        title: '发放单位',
        dataIndex: 'sendUnitName',
        ellipsis: true
    },
    {
        title: '发放人',
        dataIndex: 'sendPersonName',
        ellipsis: true
    },
    {
        title: '签收单位',
        dataIndex: 'receiveUnitName',
        ellipsis: true
    },
    {
        title: '签收人',
        dataIndex: 'receivePersonName',
        width: 200,
        ellipsis: true
    },
    {
        title: '签收日期',
        dataIndex: 'receiveTime',
        ellipsis: true
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
        width: 140,
        scopedSlots: { customRender: 'auditStatusName' }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        fixed: 'right',
        width: '230px',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '分公司',
    //     valueKey: 'branchCompanyId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '项目名称',
    //     keyValue: 'branchCompanyId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },

    {
        name: '收发文类型',
        value: 'messageType',
        type: 'select',
        data: [
            {
                value: '0',
                label: '发文'
            },
            {
                value: '1',
                label: '收文'
            }
        ]
    },
    {
        name: '文件名称',
        value: 'messageName',
        type: 'input'
    },
    {
        name: '内容摘要',
        value: 'messageAbstract',
        type: 'input'
    },
    {
        name: '发放单位',
        value: 'sendUnitName',
        type: 'input'
    },
    {
        name: '签收单位',
        value: 'receiveUnitName',
        type: 'input'
    },
    {
        name: '签收日期',
        type: 'dateRange',
        value: 'callNameDate',
        attr: {
            rangeFormat: ['updateStartTime', 'updateEndTime']
        }
    }
]
import { STable } from '@/components'
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        MoreButton
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            removeApi: { remove: deleteList }, // api

            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam })

                return getList(requestParameters).then((res) => {
                    if (res.code === '0') {
                        res.data.list.forEach((i) => {
                            i.auditStatus = ['DRAFT', 'SUBMITTED', 'UPLOAD', 'PAST', 'ABOLISH', 'REJECTED'][
                                parseInt(i.auditStatus)
                            ]
                        })
                        return {
                            code: 200,
                            data: res.data.list,
                            totalSize: res.data?.total,
                            currentPage: res.data?.pageNum
                        }
                    }
                })
            }
        }
    },

    methods: {
        //搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateDailyDataManag',
                query
            })
        }
    }
}
</script>


